<template>
    <el-dialog :visible.sync="visible" append-to-body width="70%">
        <template #title>
            <h2 style="display: inline-block;">学生评价明细</h2>
            <el-button style="float: right;margin-right: 5%;" v-print="printObj" type="success">
                打印
            </el-button>
        </template>
        <el-tabs v-model="activeName" @tab-click="handleClick">
            <el-tab-pane v-for="item in evaluateInfoArr" :key="item.evaluateId+''" :label="item.schoolYear + item.termNameText" :name="item.evaluateId+''"></el-tab-pane>
        </el-tabs>
        <el-descriptions id="printInfo" v-if="evaluateInfo" :contentStyle="contentStyle" class="margin-top" :column="3" border>
            <el-descriptions-item>
                <template slot="label">
                    学号
                </template>
                {{ evaluateInfo.registerCode }}
            </el-descriptions-item>
            <el-descriptions-item>
                <template slot="label">
                    姓名
                </template>
                {{ evaluateInfo.studentName }}
            </el-descriptions-item>
            <el-descriptions-item>
                <template slot="label">
                    学年
                </template>
                <span style="display: flex;justify-content: center;">
                    {{ evaluateInfo.schoolYear }}
                    <dict-tag :options="dict.type.basic_term_type" :value="evaluateInfo.termName"></dict-tag>
                </span>
            </el-descriptions-item>
            <el-descriptions-item>
                <template slot="label">
                    班级
                </template>
                {{ evaluateInfo.className }}
            </el-descriptions-item>
            <el-descriptions-item :span="2">
                <template slot="label">
                    院系
                </template>
                {{ evaluateInfo.college }}
            </el-descriptions-item>
            <el-descriptions-item v-for="item in evaluateInfo.evaluateScoreList" :key="item.quotaDescription">
                <template slot="label">
                    {{ item.quotaDescription }}
                </template>
                <el-tag size="small">{{ item.realScore }}</el-tag> 分
            </el-descriptions-item>
        </el-descriptions>
        <!-- <div slot="footer">
            <el-button type="primary" :loading="showLoading" @click="submit">打印</el-button>
        </div> -->
    </el-dialog>
</template>
<script>

import { schooledateList } from "@/api/information/schoolCalendar"
import {
    evaluateList,
    scoreStatisticsList,
    evaluateDetail,
    evaluateDetailDouble
} from "@/api/assessmentCenter/evaluationIndex";

export default {
    data() {
        return {
            visible: false,
            showLoading: false,
            schooleDateList: [],
            evaluationList: [],
            evaluateList: [],
            evaluateInfo: null,
            printObj: {
                id: "printInfo",    // 这里是要打印元素的ID
                popTitle: '',  // 打印的标题
                extraCss: '',  // 打印可引入外部的一个 css 文件
                extraHead: ''  // 打印头部文字
            },
            contentStyle: {
                width: '160px'
            },
            activeName: '',
            evaluateInfoArr:[],
            showType: 'row'
        }
    },
    dicts: [
        "basic_term_type"
    ],
    methods: {
        handleClick(tab, event) {
            const currentTab = this.evaluateInfoArr.find((item) => {
                return item.evaluateId + '' === tab.name
            })
            if (currentTab) {
                this.evaluateInfo = currentTab
                this.activeName = currentTab.evaluateId + ''
            } 
        },
        async init(info, type) {
            console.log(type, info,'type')
            // add or update
            this.visible = true;
            this.showType = type
            this.evaluateInfoArr = []
            this.evaluateInfo = {}
            this.activeName = ''
                const { data } = await evaluateDetailDouble(info.studentId)
                this.evaluateInfoArr = data.map((item) => {
                    const rowData = this.dict.type.basic_term_type.find((termItem) => {
                        return termItem.value == item.termName
                    })
                    return {
                        ...item,
                        termNameText: rowData.label || ''
                    }
                })
                this.evaluateInfo = data[0]
                this.activeName = data[0].evaluateId + ''
          
        
            // if (type == 'double') {
            //     const { data } = await evaluateDetailDouble(info.studentId)
            //     this.evaluateInfoArr = data.map((item) => {
            //         const rowData = this.dict.type.basic_term_type.find((termItem) => {
            //             return termItem.value == item.termName
            //         })
            //         return {
            //             ...item,
            //             termNameText: rowData.label || ''
            //         }
            //     })
            //     this.evaluateInfo = data[0]
            //     this.activeName = data[0].evaluateId + ''
            // }
            // if (type == 'row') {
            //     const { data } = await evaluateDetail(info.evaluateId)
            //     this.evaluateInfo = data
            // }
        },
        handleCancel() {
            this.visible = false;
        },
        // 获取 该学生在本学期的记录
        async getScoreList(e) {
            if (!this.dataForm.studentId) {
                return
            } else {
                const { rows } = await scoreStatisticsList({
                    studentId: this.dataForm.studentId,
                    schoolDateld: e
                })
                if (rows.length) {
                    this.dataForm.evaluateId = rows[0].evaluateId
                }

            }
        },
        // 打印
        submit() { }
    },
    async mounted() {
        const { rows } = await evaluateList()
        this.evaluateList = rows;
        rows.forEach(element => {
            this.evaluationList[element.quotaId] = 0
        });
        schooledateList().then(res => {
            this.schooleDateList = res.rows
        })
    },
}
</script>
  